<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

if (!function_exists('questionTabFieldSearch')) {

    function questionTabFieldSearch($searchData = array())
    {
        $CI = & get_instance();
        $loading = $CI->lang->line('Loading');
        $_field_search_attribute = array(
            'textsearch' => array('name' => 'textsearch', 'id' => 'frm-textsearch',
                'class' => 'span3', 'placeholder' => $CI->lang->line('Pls_enter_keyword'),
                'value' => set_value('textsearch', isset($searchData['textsearch']) ? $searchData['textsearch'] : '')
            ),
            'submit' => array('name' => 'btn-Search', 'class' => 'btn btn-primary', 'data-loading-text' => $loading,
                'id' => 'form-btnSearch', 'value' => $CI->lang->line('Search')),
            'reset' => array('name' => 'btn-Reset', 'class' => 'btn btn-primary', 'data-loading-text' => $loading,
                'id' => 'form-btnReset', 'value' => $CI->lang->line('Reset')),
        );

        return $_field_search_attribute;
    }

}


if (!function_exists('questionTabFieldFilter')) {

    function questionTabFieldFilter($filterData = array(), $filterSelected = 0)
    {
        $CI = & get_instance();
        $loading = $CI->lang->line('Loading');
        $_field_filter_attribute = array(
            'dropdown_filter' => array(
                'name' => 'subcatid',
                'data' => $filterData,
                'selected' => $filterSelected,
                'extra' => "id='frm-ia-attribute-filter' class='span3'"
            ),
            'submit' => array('name' => 'btn-Filter', 'class' => 'btn btn-primary', 'data-loading-text' => $loading,
                'id' => 'form-btnFilter', 'value' => $CI->lang->line('Filter')),
            'reset' => array('name' => 'btn-Reset', 'class' => 'btn btn-primary', 'data-loading-text' => $loading,
                'id' => 'form-btnReset', 'value' => $CI->lang->line('Reset')),
        );

        return $_field_filter_attribute;
    }

}



//define field to generate form
if (!function_exists('questionTabFieldForm')) {

    function questionTabFieldForm($tabs = array(), $cats = array(), $parentCat = array())
    {
        $CI = & get_instance();
        if (count($tabs) && !empty($tabs)) {
            $name = $tabs->name;
            $active = $tabs->active;
            $order = $tabs->order;
            $selectedCat = $tabs->cat_id;
            $selectedParentCat = $tabs->parent_cat_id;
        }
        $_field_form = array(
            'name' => array('name' => 'name', 'id' => 'frm-name',
                'class' => 'span3', 'placeholder' => $CI->lang->line('Pls_enter_question'),
                'value' => set_value('name', isset($name) ? $name : '')),
            'parent_cat_id' => array(
                'name' => 'parent_cat_id',
                'options' => $parentCat,
                'selected' => isset($selectedParentCat) ? array($selectedParentCat) : array(),
                'extra' => 'id="parentCategory"'
            ),
            'cat_id' => array(
                'name' => 'cat_id',
                'options' => $cats,
                'selected' => isset($selectedCat) ? array($selectedCat => $selectedCat) : array(),
                'extra' => 'id="childrenCategory"'
            ),
            'active' => array(
                'name' => 'active',
                'class' => 'class="checkActive"',
                'value' => 1,
                'checked' => (isset($active) && $active > 0) ? TRUE : FALSE
            ),
            'order' => array('name' => 'order', 'id' => 'frm-order',
                'class' => 'span3',
                'value' => set_value('order', isset($order) ? $order : 0)),
            'submit' => array('class' => 'btn btn-primary', 'data-loading-text' => $CI->lang->line('Loading'),
                'id' => 'form-submit', 'value' => $CI->lang->line('Save')),
        );
        return $_field_form;
    }

}

//define field to validate form
if (!function_exists('questionTabFieldValidate')) {

    function questionTabFieldValidate()
    {
        $CI = & get_instance();
        $_field_validate = array(
            array(
                'field' => 'name',
                'label' => $CI->lang->line('Question_Text'),
                'rules' => 'trim|required|xss_clean'
            ),
            array(
                'field' => 'order',
                'label' => $CI->lang->line('Order'),
                'rules' => 'trim|is_natural|xss_clean'
            ),
            array(
                'field' => 'cat_id',
                'label' => $CI->lang->line('Children_Category'),
                'rules' => 'trim|required|xss_clean'
            ),
        );
        return $_field_validate;
    }

}
